import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { h, ref } from "vue";
import { Input } from "ant-design-vue";
import { Button } from "vxe-table";
import {ajaxGetDictItems} from "@/views/system/menu/menu.api";
import {defHttp} from "@/utils/http/axios";
export const columns: BasicColumn[] = [
  {
    title: '计划编号',
    align: "center",
    dataIndex: 'planId',
    helpMessage: '年度+季度+租户+2位自增流水号。例子：2023-1-1000-01，2023-2-1000-01，2023-2-1001-02'
  },
  {
    title: '产品',
    align: "center",
    dataIndex: 'productNo_dictText'
  },
  {
    title: '计划时间',
    align: "center",
    dataIndex: 'startTime',
    slots: { customRender: 'time' },
  },

];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "计划编号",
    field: 'planId',
    component: 'Input',
    colProps: {
      span: 24
    },
  },

];
//表单数据
export const formSchema: FormSchema[] = [

  {
    label: '产品',
    field: 'productNo',
    component: 'JSearchSelect',
    componentProps: {
      dict: 't_product,name,no',
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择产品!' },
      ];
    },
  },
  {
    label: '地块',
    field: 'plotId',
    slot: 'select',
    component: 'JSearchSelect',
    componentProps: {
      dict: 't_plot,name,id',
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择地块!' },
      ];
    },
  },
  {
    label: '计划时间',
    field: 'planTime',
    component: 'RangePicker',
    componentProps: {
      style: {
        width: '100%'
      },
      showTime: false,
      valueFormat: 'YYYY-MM-DD',

    },
  },
  {
    label: '责任人',
    field: 'responsiblePerson',
    component: 'Input',
  },
  {
    label: '执行模型',
    field: 'modelId',
    component: 'ApiSelect',
    componentProps: {
      api: () => defHttp.get({ url: `/model/listAll` }),
      params: { },
      labelField: 'name',
      valueField: 'id',
      resultField:'records',
      getPopupContainer: (node) => document.body,
    },
  },

  {
    label: '状态',
    field: 'status',
    component: 'Switch',
    componentProps: {
      //开关大小，可选值：default small
      size: 'default',
      //非选中时的内容
      unCheckedChildren: '已结束',
      //非选中时的值
      unCheckedValue: 10,
      //选中时的内容
      checkedChildren: '执行中',
      //选中时的值
      checkedValue: 0,
      //是否禁用
      default: false
    },
  },
  {
    field: 'field1',
    component: 'Input',
    label: '',
    slot: 'addData',
    colProps: {
      offset: 4,

    }

  },

  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    label: '',
    field: 'planId',
    component: 'Input',
    show: false
  },

];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
